package com.xsir.ditan.miniprogram.common;

import lombok.Data;

import java.io.Serializable;

/**
 * @author user
 * @date 2021/1/28
 */
@Data
public class Result implements Serializable {
    private Integer code;
    private Object data;
    private String msg;
    
    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    
    public Result(ResultStatus status, Object data) {
        this.code = status.code();
        this.msg = status.msg();
        this.data = data;
    }
    
    public Result(Integer code, String msg) {
        this(code, msg, null);
    }
    
    public static Result error(Integer errorCode, String errorMsg) {
        return new Result(errorCode, errorMsg);
    }
    
    public static Result error(Integer errorCode) {
        return new Result(errorCode, null, null);
    }
    
    public static Result error(ResultStatus status) {
        return new Result(status,null);
    }
    
    public static Result ok(ResultStatus status, Object data) {
        return new Result(status, data);
    }
    
    public static Result ok(Object data) {
        return new Result(ResultStatus.SUCCESS, data);
    }
}
